<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width,initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv=X-UA-Compatible content="IE=edge,chrome=1">
    <meta content=always name=referrer>
    <link rel="stylesheet" type="text/css" href="__STATIC__/css/newbase.css">
    <script src="__STATIC__/js/jquery-1.8.2.js"></script>
    <title>订单管理</title>
    <style>
        .layui-m-layercont{
            padding: 30px 15px!important;
            font-size: 14px!important;
        }
        .layui-m-layer0 .layui-m-layerchild{
            width: 80%!important;
        }
        .layui-m-layershade{
            background: rgba(0,0,0,0.4)!important;
        }
    </style>
</head>
{include file="public/href" /}
<body>
<div class="wrap-man">
    <div class="header">
        <p>我的订单</p>
        <img src="__STATIC__/img_user/back.png" class="back"
             onclick=window.location.href="{:url('mobile/user_info/my_shop_index')}">
        <img src="__STATIC__/img_user/find.png" class="search"
             onclick=window.location.href="{:url('mobile/user_info/member_order_search')}">
    </div>
    <div class="center1">
        <div class="tablist">
            <ul>
                <li {eq name=":input('status','all')" value='all' }class="cur" {/eq}><a href="?status=all">全部</a></li>
                <li {eq name=":input('status','all')" value='0' }class="cur" {/eq}><a href="?status=0&title={:input('title')}">待付款</a></li>
                <li {eq name=":input('status','all')" value='1' }class="cur" {/eq}><a href="?status=1&title={:input('title')}">待发货</a></li>
                <li {eq name=":input('status','all')" value='2' }class="cur" {/eq}><a href="?status=2&title={:input('title')}">待收货</a></li>
                <li {eq name=":input('status','all')" value='3' }class="cur" {/eq}><a href="?status=3&title={:input('title')}">待评价</a></li>
                <li {eq name=":input('status','all')" value='4' }class="cur" {/eq}><a href="?status=4&title={:input('title')}">已完结</a></li>
                <li {eq name=":input('status','all')" value='6,9,10,11' }class="cur" {/eq}><a href="?status=6,9,10,11&title={:input('title')}">退换货</a></li>
            </ul>
        </div>
        <div class="tabcon">
            <div class="cur" id="order_list">

            </div>
            <div></div>
        </div>
    </div>

</div>
{include file="public/src" /}
<script>
    //跳转到店铺
    function jump_shop(id) {
        var url = "{:url('mobile/user_category/shop_index')}?shop_id=" + id;
        sessionStorage.setItem('shop_back_url', window.location.href);
        window.location.href = url;
    }

    //layer流加载
    layui.use('flow', function () {
        var $ = layui.jquery;
        var flow = layui.flow;
        flow.load({
            elem: '#order_list' //流加载容器
            , isAuto: true
            , isLazyimg: true
            , done: function (page, next) { //执行下一页的回调
                var lis = [];
                $.ajax({
                    url: "{:url('mobile/user_info/member_order')}",
                    dataType: 'json',
                    type: 'post',
                    data: {'page': page, 'status': "{:input('status')}", 'title': "{:input('title','')}"},

                    success: function (t) {

                        layui.each(t.data, function (index, item) {
                            //订单处理方式
                            var statusArr = [
                                '付款',
                                '申请退款',
                                '查看物流',
                                '去评价',  //已转移
                                '已完结',  //不显示
                                '已取消',  //不含此类型订单
                                '退款/货详情',  //不显示
                                '退款审核成功 ',
                                '退款审核失败',
                                '退货中',
                                '退款/退货成功',
                                '退款/退货失败',

                            ];

                            //额外处理订单的方式及路径
                            var addedUrl = [
                                'javascript:order_cancel(' + item.id + ',' + item.shop_id + ');',   //取消订单
                                '',
                                'javascript:order_confirm(' + item.id + ');',    //已收货
                                'javascript:return_goods(' + item.id + ');',   //申请退换货
                                '',
                                '',
                                '', //退款详情
                                '',
                                '',
                                '',
                                '',
                                '',
                                '',
                            ];
                            var addedStatus = [
                                '<span class="qx"><a href="' + addedUrl[item.status] + '">取消订单</a></span>',
                                '',
                                '<span class="qx"><a href="' + addedUrl[item.status] + '">确认收货</a></span>',
                                '<span class="qx"><a href="' + addedUrl[item.status] + '">申请退换货</a></span>',
                                '',
                                '',
                                '',
                                '',
                                '',
                                '',
                                '',
                                '',
                                '',
                            ];

                            //处理订单方式的跳转路径
                            var statusUrl = [
                                'javascript:pay_now(' + item.id + ');',
                                'javascript:return_goods(' + item.id + ');',   //申请退款
                                'javascript:see_express(' + item.id + ');',  //查看物流
                                '', //立即评价(已转到单商品里)
                                'javascript:void(0);',  //已完结
                                'javascript:void(0);',  //已取消
                                'javascript:return_details(' + item.id + ');',  //退款详情
                                'javascript:return_details(' + item.id + ');',   //已退款
                                'javascript:return_details(' + item.id + ');',   //已退款
                                'javascript:return_details(' + item.id + ');',   //已退款
                                'javascript:return_details(' + item.id + ');',   //已退款
                                'javascript:return_details(' + item.id + ');',   //已退款
                            ];

                            var text = '<span class="qx"><a href="' + statusUrl[item.status] + '">' + statusArr[item.status] + '</a></span>';
                            if (item.status == 3 || item.status == 4) {
                                text = '';
                            }
                            //订单状态
                            var orderStatus = ['待付款', '待发货', '待收货', '已收货', '已完结', '已取消', '等待审核中', '退款审核成功','退款审核失败','退货中','退款/退货成功','退款/退货失败'];

                            //循环店铺内商品
                            var goods = '';
                            if (item.memberOrderAttached.length > 0) {
                                for (var i = 0; i < item.memberOrderAttached.length; i++) {
                                    var attr = '无属性';
                                    if (item.memberOrderAttached[i].attr) {
                                        attr = item.memberOrderAttached[i].attr;
                                    }
                                    //立即评价跳转
                                    var evaluate = '';
                                    if (item.status == 3) {
                                        if (item.memberOrderAttached[i].status == 1) {
                                            evaluate = '<span style="color: #e02e24;border: 1px solid #e02e24;;border-radius:10%;padding:0 5px ;float: right"><a href="javascript:void(0);" style="color: #e02e24;">已评价</a></span>';
                                        } else {
                                            evaluate = '<span style="color: #e02e24;border: 1px solid #e02e24;;border-radius:10%;padding:0 5px ;float: right"><a href="javascript:to_evaluate(' + item.memberOrderAttached[i].id + ');" style="color: #e02e24;">去评价</a></span>';
                                        }

                                    }
                                    goods += '<div class="content">' +
                                            '<div class="left">' +
                                            '<img src="/' + item.memberOrderAttached[i].thumb_img + '" onerror=this.src="/static/mobile/img/empty_img.png" >' +
                                            '</div>' +
                                            '<div class="right">' +
                                            '<div class="title">' +
                                            '<span class="titleList" onclick="jump_goods_details(' + item.memberOrderAttached[i].goods_id + ')">' + item.memberOrderAttached[i].title + '</span>' + evaluate +
                                            '</div>' +
                                            '<p class="type">属性规格：' + attr + '<span>×' + item.memberOrderAttached[i].number + '</span></p>' +
                                            '<div class="price">' +
                                            '<div>&yen;' + item.memberOrderAttached[i].price + '</div>' +
                                            '</div>' +
                                            '</div>' +
                                            '</div>'
                                }
                            }
                            if (item.memberOrderAttached.length > 0) {
                                lis.push('<div id="main" >' +
                                        '<h4 onclick="jump_shop(' + item.shop_id + ')">' +
                                        '<span>&nbsp;' + item.shop.title + '  </span>' +
                                        '<img src="__STATIC__/img_user/next2.png" />' +
                                        '<span class="right1"><font>' + orderStatus[item.status] + '</font></span>' +
                                        '</h4>' + goods +
                                        '<div class="tuikuan" onclick="jump_order_details(' + item.id + ')" >' +
                                        '<p>共' + item.total_num + '件商品  &nbsp;&nbsp;&nbsp;  合计：<font style="color:#e02e24;"> &yen;' + item.pay_money + ' </font> </span></p>' +
                                        '</div>' +
                                        '<div class="order" style="border-bottom: 1px solid #F0F0F0;margin-bottom: 1.5%">'
                                        + addedStatus[item.status] +
                                        text +
                                        '<input type="hidden" name="number_' + item.id + '" value="' + item.shop_order_number + '" ' +
                                        '</div>' +
                                        '</div>');
//                                (运费:<font style="color: red;">&yen;' + item.freight + '</font>)
                            }

                        });
                        next(lis.join(''), page < t.pages);
                    },
                    error: function () {
                        layer.open({content: '网络繁忙,请重试', skin: 'msg', time: 2});
                    }
                })
            }
        });
    });

    //跳转到订单详情
    function jump_order_details(id) {
        window.location.href = "{:url('mobile/user_info/member_order_details')}?order_id=" + id + "&status={:input('status')}&title={:input('title')}";
    }
    //取消订单
    function order_cancel(id, shop_id) {
        var number = $("[name=number_" + id + "]").val();
        layer.open({
            content: '您确定要取消此订单吗？'
            , btn: ['确定', '取消']
            , yes: function (index) {
                $.post("{:url('mobile/member_order/cancel')}", {'number': number, 'shop_id': shop_id}, function (data) {
                    if (data.code == 200) {
                        layer.open({content: data.message, skin: 'msg', time: 2});
                        setTimeout(function () {
                            window.location.href = "?status=all"
                        }, 2000);
                    } else {
                        layer.open({content: data.message, skin: 'msg', time: 2})
                    }
                });
                layer.close(index);
            }
        });
    }
    //去付款
    function pay_now(oid) {
        sessionStorage.setItem('oid', oid);
        layer.open({content: '正在跳转支付页面...', skin: 'msg', time: 2});
        setTimeout(function () {
            window.location.href = "{:url('mobile/user_category/choose_pay_type')}?status={:input('status')}&title={:input('title')}&oid=" + oid;
        }, 2000);
    }
    //去评价
    function to_evaluate(order_id) {
        sessionStorage.setItem('evaluate_back_url', window.location.href);
        window.location.href = "{:url('mobile/member_order/goods_evaluate')}?order_id=" + order_id + "&status={:input('status')}&title={:input('title')}";
    }
    //查看物流
    function see_express(id) {
        $.ajax({
            url: "{:url('mobile/member_order/refund_details')}?order_id=" + id,
            dataType: 'json',
            type: 'post',
            success: function (data) {
                if (data.code == 400) {
                    layer.open({content: data.message, skin: 'msg', time: 2})
                } else {
                    window.location.href = "{:url('mobile/member_order/refund_details')}?status={:input('status')}&order_id=" + id + "&title={:input('title')}";
                }
            },
            error: function () {
                layer.open({content: '网络繁忙,请重试', skin: 'msg', time: 2});
            }
        })
    }
    //已收货
    function order_confirm(id, shop_order_number) {
        layer.open({
            content: '确定已收货吗？'
            , btn: ['确定', '取消']
            , yes: function (index) {
                $.ajax({
                    url: "{:url('mobile/member_order/order_confirm')}",
                    data: {'order_id': id},
                    type: 'post',
                    dataType: 'json',
                    success: function (data) {
                        if (data.code == 200) {
                            layer.open({content: data.message, skin: 'msg', time: 2});
                            setTimeout(function () {
                                window.location.reload();
                            }, 2000);
                        } else {
                            layer.open({content: data.message, skin: 'msg', time: 2});
                        }
                    },
                    error: function () {
                        layer.open({content: '网络繁忙,请重试', skin: 'msg', time: 2});
                    }
                });
                layer.close(index);
            }
        });
    }
    //退换货
    function return_goods(order_id) {
        window.location.href = "{:url('mobile/member_order/return_money')}?order_id=" + order_id + "&status={:input('status','all')}&title={:input('title')}";
    }
    //查看退款详情
    function return_details(id) {
        window.location.href = "{:url('mobile/member_order/return_details')}?order_id=" + id + "&status={:input('status')}&title={:input('title')}"
    }
    //跳转到商品详情
    function jump_goods_details(id) {
        sessionStorage.setItem('goods_url_back', window.location.href);
        window.location.href = "{:url('mobile/user_category/goods_details')}?goods_id=" + id;
    }
</script>
</body>
</html>